package com.ddd.core.utils;

import org.springframework.util.ObjectUtils;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * @description:
 * @author: zhongwenbin
 * @date: 2024-10-22 20:25
 **/
public class SwaggerUtils {

    /**
     * 创建一个 Docket
     *
     * @param basePackage 包路径
     * @param antPattern  url路径
     * @return
     */
    public static Docket createDocket(String basePackage,
                                       String antPattern) {
        return new Docket(DocumentationType.SWAGGER_2)
                .enable(true)
                .select()
                .apis(
                        ObjectUtils.isEmpty(basePackage) ?
                                RequestHandlerSelectors.any() :
                                RequestHandlerSelectors.basePackage(basePackage))
                .paths(
                        ObjectUtils.isEmpty(antPattern) ?
                                PathSelectors.any() :
                                PathSelectors.ant(antPattern))
                .build();
    }

    public static ApiInfo createApiInfo(String title, String description, String version) {
        return new ApiInfoBuilder()
                .title(title)
                .description(description)
                .version(version)
                .build();
    }

}


